<?php

use Core\API_Controller;
use Models\Region;

class RegionController extends API_Controller
{
	public function index($parent_id = 1)
	{
		$regions = Region::where('parent_id', $parent_id)->get();
		foreach ($regions as $key => $value) {
			if($value['type'] < 3) {
				$regions[$key]['children'] = [];
			}
		}

		return $this->success([
			'regions' => $regions
		]);
	}
}